'use strict';
const db = uniCloud.database()
const dbCmd = db.command
const aggregate = dbCmd.aggregate
function getField(field){
	let empty={};
	let arr = field.split(',');
	arr.map(v=>empty[v]=true)
	return empty;
}
exports.main = async (event, context) => {
	const collection = db.collection('traveler')
	const _id = event.id;
	const filter = {};
	_id ? filter._id = _id:'';
	let res = await collection
	.where(filter)
	.field(getField("certificateNum,certificateType,name,phone,sex,_id"))
	// .limit(1)
	.get()
	res.data = _id?res.data[0]:res.data;
	return res
};
